//
//  DLLucreView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/11/26.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLLucreView.h"
#import "DLYesterdayIncomeVC.h"
#import "DLTotalIncomeVC.h"

@implementation DLLucreView


- (instancetype) initWithFrame:(CGRect)frame andTitle:(NSString *)title andCount:(NSString *)count {
    
    if (self = [super initWithFrame:frame]) {
        
        [self layoutSubControlsWithTitle:title andCount:count];
        
        UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(functionViewTap)];
        [self addGestureRecognizer:tapGes];
    }
    return self;
}
- (void) functionViewTap {
    
    if ([self.titleLabel.text isEqualToString:@"昨日收益(元)"]) {
        DLYesterdayIncomeVC *yesterdayIncomeVC = [DLYesterdayIncomeVC new];
        [kuserManager.lastVc.navigationController pushViewController:yesterdayIncomeVC animated:YES];
    } else if ([self.titleLabel.text isEqualToString:@"累计收益(元)"]) {
//        DLTotalIncomeVC *totalIncomeVC = [DLTotalIncomeVC new];
//        [kuserManager.lastVc.navigationController pushViewController:totalIncomeVC animated:YES];
        DLYesterdayIncomeVC *yesterdayIncomeVC = [DLYesterdayIncomeVC new];
        [kuserManager.lastVc.navigationController pushViewController:yesterdayIncomeVC animated:YES];
    }
}

- (void) layoutSubControlsWithTitle:(NSString *)title andCount:(NSString *)count{
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.frame = CGRectMake(0, 0, self.width, kAutoWidth(30));
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.font = kSystemFont(13);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:titleLabel];
    titleLabel.text = title;
    self.titleLabel = titleLabel;
    
    
    UILabel *countLabel = [UILabel new];
    countLabel.frame = CGRectMake(0, titleLabel.bottom, self.width, kAutoWidth(30));
    countLabel.textColor = [UIColor whiteColor];
    countLabel.font = kSystemFont(13);
    countLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:countLabel];
    countLabel.text = count;
    self.countLabel = countLabel;
    
}

- (void) updateUserinfo {
    
    switch (self.tag) {
        case 12138:
        {
            self.countLabel.text = kuserManager.userInfoModel.yesterdayIncome;
        }
            break;
        case 12139:
        {
            self.countLabel.text = kuserManager.userInfoModel.totalIncome;
        }
            break;
        case 12140:
        {
            self.countLabel.text = [NSString stringWithFormat:@"%.2f\%%", kuserManager.userInfoModel.rate];
        }
            break;
        default:
            break;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
